package com.xls.commonlibrary.base;

import android.os.Bundle;
import android.view.MotionEvent;

import androidx.appcompat.app.AppCompatActivity;

import com.hjq.toast.Toaster;
import com.xls.commonlibrary.util.ActivityUtil;
import com.xls.commonlibrary.util.eventbus.MessageEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;


public abstract class BaseActivity extends AppCompatActivity {

    // todo : 统一状态栏，加载框，toast，监听的添加和注销


    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            // 判断连续点击事件时间差
            if (ActivityUtil.isFastClick()) {
                return true;
            }
        }
        return super.dispatchTouchEvent(event);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);


    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        EventBus.getDefault().unregister(this);
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventReceived(MessageEvent event) {
        //TODO     子类必须调用 不然报错
    }

    public void toast(String msg) {
        Toaster.show(msg); // 任何时候都弹
//        Toaster.debugShow(msg); // 只有debug才弹出
    }

    public void toastDebug(String msg) {
//        Toaster.show(msg); // 任何时候都弹
        Toaster.debugShow(msg); // 只有debug才弹出
    }

}
